﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ecdl.demo.model;
using ecdl.demo.model.util;
using ecdl.demo.ui;
using ecdl.demo.ui.question;
using ecdl.demo.model.file;
using ecdl.demo.ui.task;
using ecdl.demo.model.word;
using ecdl.demo.model.question;
using ecdl.demo.model.expression;
using ecdl.demo.persistence;
using ecdl.demo.ui.ui.test;

using Ninject;
using Ninject.Modules;


namespace ecdl.demo.application {
    public class DemoTestModule : NinjectModule{

        public override void Load() {

            BindPresenters();

            Bind<ITestTimer>().To<StandardTestTimer>();
            Bind<IVolumeProvider>().To<VirtualDriveProvider>().InSingletonScope();
            
            BindWordClasses();

            BindPersistenceContributors();
            BindTaskProviders();

        }

        private void BindPresenters() {
            Bind<ITaskPresenter>().To<QuestionaireWindow>().InSingletonScope();
            Bind<ITestPresenter>().To<TestRunWindow>().InSingletonScope();
            Bind<ITaskEvaluationPresenter>().To<TaskEvaluationWindowFactory>();
            Bind<ITestEvaluationPresenter>().To<TestEvaluation>();
        }

        private void BindPersistenceContributors() {
            Bind<IPersistenceContributor>().To<ExpressionPersistenceContributor>();
            Bind<IPersistenceContributor>().To<TestPersistenceContributor>();
            Bind<IPersistenceContributor>().To<QuestionPersistenceContributor>();
            Bind<IPersistenceContributor>().To<FileTaskPersistenceContributor>();
            Bind<IPersistenceContributor>().To<WordTaskPersistenceContributor>();

        }

        private void BindTaskProviders() {
            Bind<ITaskProvider>().ToConstant(WordTaskCatalog.GetDefaultCatalogue());
            Bind<ITaskProvider>().ToConstant(Questionaire.GetDefaultQuestionaire());
            Bind<ITaskProvider>().ToConstant(FileTaskCatalogue.GetDefaultCatalogue()); 
        }

        private void BindWordClasses() {
            Bind<IDocxLoader>().To<DefaultDocxLoader>();
        }
    }

    public class TaskEvaluationWindowFactory : ITaskEvaluationPresenter {

        private IKernel injector;
        public TaskEvaluationWindowFactory(IKernel injector) {
            this.injector = injector;
        }

        public void ShowTaskEvaluation(bool isCorrect, string cause) {
            //return a new taskevaluationPresenter
            ITaskEvaluationPresenter presenter = injector.Get<TaskEvaluationWindow>();
            presenter.ShowTaskEvaluation(isCorrect, cause);
        }
    }
}
